﻿/*
#------------------------------------------------------------------------------
#-- Program Name:	[dbo].[fnMSX_get_version]
#-- Purpose:		Convert a four position version number into either the first
#--					position number (@get_major_version = 1) or the second
#--					position number (@get_major_version = 0)
#--					Ex. 10.5.1600.0
#--	Last Update:	07/31/2012
#--					For a complete history - please review comments in Version
#--					Control.
#------------------------------------------------------------------------------
*/
CREATE FUNCTION [dbo].[fnMSX_get_version]
(
	@product_version			varchar(25),
	@get_major_version			bit
)
RETURNS INT
AS
BEGIN
	DECLARE @retval int

	IF ISNULL(@get_major_version, 1) = 1
	  BEGIN
		SET @retval = CONVERT(int, (CASE	WHEN PARSENAME(CONVERT(varchar, @product_version, 0), 4) IS NULL 
												THEN PARSENAME(CONVERT(varchar, @product_version, 0), 3) 
											ELSE PARSENAME(CONVERT(varchar, @product_version, 0), 4) 
											END)
								, 0)
	  END
	ELSE
	  BEGIN
		SET @retval = CONVERT(int, (CASE	WHEN PARSENAME(CONVERT(varchar, @product_version, 0), 4) IS NULL 
												THEN PARSENAME(CONVERT(varchar, @product_version, 0), 2) 
											ELSE PARSENAME(CONVERT(varchar, @product_version, 0), 3) 
											END)
								, 0)
	  END

	RETURN @retval
END
